package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@ResponseBody
public class OrderController {

    public static Map<Long,Double> mapProduce = new HashMap<Long,Double>();
    static {
        mapProduce.put(1L,5000D);
    }


    @GetMapping("getPrice/{productId}/{discount}")
    public Double getPrice(@PathVariable Long productId, @PathVariable String discount) {
        if (null == productId) {
            return null;
        }
        Double price = getProduct(productId);
        switch (discount) {
            case "rate":
                price = price * 0.9;
            case "maxout":
                if (price > 5000) {
                    price = price -100;
                }
        }
        return price;
    }

    public Double getProduct(Long productId) {

        return mapProduce.get(productId);
    }
}
